package org.example.spring.carsalemanagementsystem.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Integer code;
    private String msg;
    private Object data;
    private Result(ResultCodeEnum resultCodeEnum){
        this.code= resultCodeEnum.getCode();
        this.msg=resultCodeEnum.getMsg();
    }
    /**
     * 返回不带数据的成功
     */
    public static Result success(){
        return new Result(ResultCodeEnum.SUCCESS);
    }
    /**
     * 返回不带数据的失败
     * 默认状态码
     */
    public static Result error(){
        return new Result(ResultCodeEnum.ERROR);
    }
    /**
     * 返回不带数据的失败
     */
    public static Result error(ResultCodeEnum resultCodeEnum){
        return new Result(resultCodeEnum);
    }
    /**
     * 添加数据
     * 如果data未初始化则初始化data
     * 返回this形成链式调用
     */
    public Result put(Object data){
        this.data=data;
        return this;
    }
}
